<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @cancel="handleCancel"
    cancelText="关闭">
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
    </template>

    <a-spin :spinning="confirmLoading">
      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
               :dataSource="dataSource" :loading="loading" class="j-table-force-nowrap" >
      </a-table>
    </a-spin>

  </j-modal>
</template>

<script>
import { jxSelect } from '@/api/apiDs'

export default {
  name: 'TaskSqlJXModal',
  data() {
    return {
      confirmLoading: false,
      loading: false,
      dataSource: [],
      title: '即席查询',
      visible: false,
      width:800,
      columns: []
    }
  },
  methods: {
    showTable(tid) {
      this.visible = true
      let param = {tid:tid}
      jxSelect(param).then(res => {
        if (res.success) {
          let datas = res.result
          let data = datas[0]
          for(let key in data){
             let param =  {
                 title: key,
                 align: "center",
                 dataIndex: key,
                 ellipsis: true,
                 key: ''+Math.random()
               }
             this.columns.push(param)
          }
          this.dataSource = datas
        } else {
          this.$message.warning(res.message)
          this.visible = true
        }
      })

    },

    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>